//-----------------------------------------------------------------------
// <copyright file="a_Avail_PaymentTypeDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_Avail_PaymentTypeDAOBase
    {
        #region Common methods
        public virtual a_Avail_PaymentType Createa_Avail_PaymentTypeFromReader(IDataReader reader)
        {
            a_Avail_PaymentType item = new a_Avail_PaymentType();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("PaymentID"))) item.PaymentID = (int)reader["PaymentID"];
                if (!reader.IsDBNull(reader.GetOrdinal("InstruTypeID"))) item.InstruTypeID = (int)reader["InstruTypeID"];
                if (!reader.IsDBNull(reader.GetOrdinal("PaymentType"))) item.PaymentType = (string)reader["PaymentType"];
                if (!reader.IsDBNull(reader.GetOrdinal("Linkpoint"))) item.Linkpoint = (bool)reader["Linkpoint"];
                if (!reader.IsDBNull(reader.GetOrdinal("AllGateway"))) item.AllGateway = (bool)reader["AllGateway"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_Avail_PaymentType methods
            
        public virtual void Createa_Avail_PaymentType(a_Avail_PaymentType a_Avail_PaymentType)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Avail_PaymentTypes_ins");
                
                database.AddInParameter(dbCommand, "@InstruTypeID", DbType.Int32, a_Avail_PaymentType.InstruTypeID);
                database.AddInParameter(dbCommand, "@PaymentType", DbType.AnsiString, a_Avail_PaymentType.PaymentType);
                database.AddInParameter(dbCommand, "@Linkpoint", DbType.Boolean, a_Avail_PaymentType.Linkpoint);
                database.AddInParameter(dbCommand, "@AllGateway", DbType.Boolean, a_Avail_PaymentType.AllGateway);
                database.AddOutParameter(dbCommand, "@PaymentID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_Avail_PaymentType.PaymentID = (int)database.GetParameterValue(dbCommand, "@PaymentID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_Avail_PaymentType methods
        
        public virtual void Updatea_Avail_PaymentType(a_Avail_PaymentType a_Avail_PaymentType)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Avail_PaymentTypes_upd");            
                
                database.AddInParameter(dbCommand, "@PaymentID", DbType.Int32, a_Avail_PaymentType.PaymentID);
                database.AddInParameter(dbCommand, "@InstruTypeID", DbType.Int32, a_Avail_PaymentType.InstruTypeID);
                database.AddInParameter(dbCommand, "@PaymentType", DbType.AnsiString, a_Avail_PaymentType.PaymentType);
                database.AddInParameter(dbCommand, "@Linkpoint", DbType.Boolean, a_Avail_PaymentType.Linkpoint);
                database.AddInParameter(dbCommand, "@AllGateway", DbType.Boolean, a_Avail_PaymentType.AllGateway);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_Avail_PaymentType methods
        public virtual void Deletea_Avail_PaymentType(int paymentID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Avail_PaymentTypes_del");
                
                database.AddInParameter(dbCommand, "@PaymentID", DbType.Int32, paymentID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_Avail_PaymentType methods
        
        public virtual a_Avail_PaymentType Geta_Avail_PaymentType(int paymentID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Avail_PaymentTypes_sel");
                
                database.AddInParameter(dbCommand, "@PaymentID", DbType.Int32, paymentID);
                
                a_Avail_PaymentType a_Avail_PaymentType =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_Avail_PaymentType = Createa_Avail_PaymentTypeFromReader(reader);
                        reader.Close();
                    }
                }
                return a_Avail_PaymentType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_Avail_PaymentTypeList methods
        public virtual a_Avail_PaymentTypeCollection Geta_Avail_PaymentTypeList(a_Avail_PaymentTypeColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Avail_PaymentTypes_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_Avail_PaymentTypeCollection a_Avail_PaymentTypeCollection = new a_Avail_PaymentTypeCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_Avail_PaymentType a_Avail_PaymentType = Createa_Avail_PaymentTypeFromReader(reader);
                        a_Avail_PaymentTypeCollection.Add(a_Avail_PaymentType);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_Avail_PaymentTypeCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_Avail_PaymentTypeCollection Geta_Avail_PaymentTypeList(a_Avail_PaymentTypeColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_Avail_PaymentTypeList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}